﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MapViewer.MainWindow"
	xmlns:nbt="clr-namespace:NamedBinaryTag;assembly=NamedBinaryTag"
	xmlns:nbtc="clr-namespace:NamedBinaryTag.Converters;assembly=NamedBinaryTagConverters"
	xmlns:mmc="clr-namespace:Minecraft.Map.Converters;assembly=MapConverters"
	xmlns:mvm="clr-namespace:MapViewer.Model"
        Title="Minecraft Map Viewer" ScrollViewer.VerticalScrollBarVisibility="Auto" SizeToContent="WidthAndHeight" ResizeMode="NoResize">
	<Window.Resources>
		<nbt:TagFile x:Key="SourceFile" />
		<nbtc:TagPathValueConverter x:Key="TagValueConverter" />
		<mmc:DimensionConverter x:Key="DimensionConverter" />
		<mmc:MapImageConverter x:Key="MapImageConverter" WidthName="width" HeightName="height" DataName="colors" />
		<Storyboard x:Key="FileEnter">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="button">
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
					<EasingDoubleKeyFrame.EasingFunction>
						<CubicEase EasingMode="EaseIn"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
		<Storyboard x:Key="FileLeave">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="button">
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.2">
					<EasingDoubleKeyFrame.EasingFunction>
						<CubicEase EasingMode="EaseOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
		<DataTemplate x:Key="RecentItemDataTemplate" DataType="{x:Type mvm:DesignerRecentItem}">
			<MenuItem Header="{Binding Title, Mode=OneWay}" Click="MenuItem_Click" />
		</DataTemplate>
		<Storyboard x:Key="LoadingAnimation" RepeatBehavior="Forever">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="image">
				<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:2" Value="360"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
		<RoutedCommand x:Key="RecentCommand" />
		<RoutedCommand x:Key="RecentMenuCommand" />
		<RoutedCommand x:Key="OpenCommand" />
		<Style x:Key="RecentMenuItemStyle" TargetType="{x:Type MenuItem}">
			<Setter Property="Header" Value="{Binding Title, Mode=OneWay}" />
			<Setter Property="Command" Value="{StaticResource RecentCommand}" />
			<Setter Property="CommandParameter" Value="{Binding}"/>
		</Style>
	</Window.Resources>
	<Window.CommandBindings>
		<CommandBinding Command="{StaticResource RecentCommand}" Executed="Recent_Executed"
				CanExecute="Recent_CanExecute" />
		<CommandBinding Command="{StaticResource RecentMenuCommand}" CanExecute="RecentMenu_CanExecute" />
		<CommandBinding Command="{StaticResource OpenCommand}" CanExecute="Open_CanExecute" Executed="Open_Executed" />
		<CommandBinding Command="ApplicationCommands.Open" CanExecute="Open_CanExecute" Executed="Open_Executed" />
	</Window.CommandBindings>
	<Grid x:Name="ContentPane">
		<Grid x:Name="DataPane" DataContext="{Binding Source={StaticResource SourceFile}}" d:LayoutOverrides="Width">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Label Content="Fichier"/>
			<StackPanel Grid.Column="1" VerticalAlignment="Center">
				<TextBlock x:Name="fileName" HorizontalAlignment="Left" TextWrapping="Wrap" Width="200"
					/>
			</StackPanel>
			<StackPanel x:Name="fileButtonStackPanel" Grid.Column="1" VerticalAlignment="Top" MouseEnter="fileName_MouseEnter" MouseLeave="fileName_MouseLeave">
				<Menu x:Name="button" HorizontalAlignment="Right">
					<MenuItem Header="Parcourir…">
						<MenuItem Header="Recents" ItemsSource="{DynamicResource RecentItems}" ItemContainerStyle="{DynamicResource RecentMenuItemStyle}"
								Command="{StaticResource RecentMenuCommand}" />
						<Separator/>
						<MenuItem Header="Fichier…" Command="ApplicationCommands.Open" CommandParameter="File" />
						<MenuItem Header="Dossier…" Command="{StaticResource OpenCommand}"
								CommandParameter="Folder" />
						<MenuItem Header="Url…" Command="{StaticResource OpenCommand}"
								CommandParameter="Url" />
					</MenuItem>
				</Menu>
			</StackPanel>
			<Label Content="Résolution" Grid.Row="1"/>
			<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="2">
				<TextBlock x:Name="width" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Right" HorizontalAlignment="Left"
					Text="{Binding ConverterParameter=data.width, Converter={StaticResource TagValueConverter}}"
					DataContext="{Binding RootTag}"/>
				<Label Content="╳" HorizontalAlignment="Center" VerticalAlignment="Center"/>
				<TextBlock x:Name="height" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center"
					Text="{Binding ConverterParameter=data.height, Converter={StaticResource TagValueConverter}}"
					DataContext="{Binding RootTag}"/>
			</StackPanel>
			<Label Content="Centre" Grid.Row="2"/>
			<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" Grid.ColumnSpan="2">
				<TextBlock x:Name="centerX" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Right" HorizontalAlignment="Left"
					Text="{Binding ConverterParameter=data.xCenter, Converter={StaticResource TagValueConverter}}"
					DataContext="{Binding RootTag}"/>
				<Label Content="╳" HorizontalAlignment="Center" VerticalAlignment="Center"/>
				<TextBlock x:Name="centerZ" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center"
					Text="{Binding ConverterParameter=data.zCenter, Converter={StaticResource TagValueConverter}}"
					DataContext="{Binding RootTag}"/>
			</StackPanel>
			<Label Content="Échelle" Grid.Row="3"/>
			<StackPanel Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal">
				<TextBlock x:Name="scale" TextWrapping="Wrap" d:LayoutOverrides="Width"
					Text="{Binding ConverterParameter=data.scale, Converter={StaticResource TagValueConverter}}" HorizontalAlignment="Left" VerticalAlignment="Center" DataContext="{Binding RootTag}" />
			</StackPanel>
			<Label Content="Dimension" Grid.Row="4"/>
			<StackPanel Grid.ColumnSpan="2" Grid.Row="4" Grid.Column="1" Orientation="Horizontal">
				<TextBlock x:Name="dimension" TextWrapping="Wrap" VerticalAlignment="Center"
					Text="{Binding ConverterParameter=data.dimension, Converter={StaticResource DimensionConverter}}" HorizontalAlignment="Left" DataContext="{Binding RootTag}" />
			</StackPanel>
			<Image Grid.Row="5" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Top"
				Source="{Binding ConverterParameter=data, Converter={StaticResource MapImageConverter}}"
				DataContext="{Binding RootTag}" Stretch="None" RenderTransformOrigin="0.5,0" >
				<Image.RenderTransform>
					<TransformGroup>
						<ScaleTransform ScaleX="1" ScaleY="1"/>
						<SkewTransform/>
						<RotateTransform/>
						<TranslateTransform/>
					</TransformGroup>
				</Image.RenderTransform>
			</Image>
		</Grid>
		<Border x:Name="LoadPane" Background="#CA000000" Visibility="Hidden">
			<Image x:Name="image" Source="loader.gif" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
				<Image.RenderTransform>
					<TransformGroup>
						<ScaleTransform/>
						<SkewTransform/>
						<RotateTransform/>
						<TranslateTransform/>
					</TransformGroup>
				</Image.RenderTransform>
			</Image>
		</Border>
	</Grid>
</Window>
